﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class ListJobsFrist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["AdminLogin2"] != null)
                {
                    int atid = Convert.ToInt32(Session["AdminLogin2"]);

                    Bind(atid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["AdminLogin2"] != null)
            {
                int atid = Convert.ToInt32(Session["AdminLogin2"]);

                Bind(atid);
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_isFrist")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_rid = Convert.ToInt32(e.CommandArgument);

                    lcmyjobs.BLL.enterprise_releasejob ej = new BLL.enterprise_releasejob();

                    if (ej.UpdateWhere("status", "3", enterprise_rid.ToString()))//status字段3代表急聘审核通过
                    {
                        //Maticsoft.Common.MessageBox.Show(this, "急聘成功！");
                        if (Session["AdminLogin2"] != null)
                        {
                            int atid = Convert.ToInt32(Session["AdminLogin2"]);

                            Bind(atid);
                        }
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "急聘失败！");
                    }
                }

            }
        }

        private void Bind(int atid)
        {
            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetAllIsFristRelesJobByAtid(atid,this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            this.lbl_count.Text = count.ToString();

            int recordCount = 0;

            if (ds.Tables[1].Rows.Count > 0)
            {
                recordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            }
             

            this.AspNetPager1.RecordCount = count;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
        //急聘
        protected void lbn_check_Click(object sender, EventArgs e)
        {
            lcmyjobs.BLL.enterprise_releasejob ej = new BLL.enterprise_releasejob();

            string enterprise_rid = this.GetSelIDlist();

            if (ej.UpdateWhere("status", "3", enterprise_rid))//status字段3代表急聘审核通过
            {
                if (Session["AdminLogin2"] != null)
                {
                    int atid = Convert.ToInt32(Session["AdminLogin2"]);

                    Bind(atid);
                }
            }

        }
        //取消急聘
        protected void lbn_up_Click(object sender, EventArgs e)
        {
            lcmyjobs.BLL.enterprise_releasejob ej = new BLL.enterprise_releasejob();

            string enterprise_rid = this.GetSelIDlist();

            if (ej.UpdateWhere("status", "1", enterprise_rid))//status字段3代表急聘审核通过
            {
                if (Session["AdminLogin2"] != null)
                {
                    int atid = Convert.ToInt32(Session["AdminLogin2"]);

                    Bind(atid);
                }
            }
        }
        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)GridView1.Rows[i].FindControl("cbo_rid");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
      

    }
}